<template>
	<view class="container">
		<cu-bar2 bgColor="bg-orange" :isBack="false">
			<block slot="content" class="page-name text-white">首页</block>
		</cu-bar2>
		<view class="contents-tabar">
			<view class="bg-white padding-bottom margin-top-sm">
				<swiper :datas="swiperList" @onchange="OnSwiper"></swiper>
			</view>
			<view class="bg-white margin-top">
				<uni-navbar :datas="tabars" @onchange="onNavBar"></uni-navbar>
			</view>
			<cu-grid-case :datas="lists" @onclick="OnClickLive"></cu-grid-case>
			<cu-more :title="loadMoreText"></cu-more>
		</view>
		<tabbar isBottom="true" :selectIndex="0" @onswitch="onSwitch"></tabbar>
	</view>
</template>

<script>
	import swiper from '../../components/single/swiper/swiper.vue';
	import uniNavbar from '../../components/single/nav/uni-navbar.vue'
	import cuGridCase from '../../components/single/grid/cu-grid-case.vue';
	import {
		mapState,
		mapMutations
	} from 'vuex';
	export default {
		computed: mapState(['hasLogin', 'userinfo', 'inviter', 'islive']),
		components: {
			uniNavbar,
			cuGridCase,
			swiper
		},
		data() {
			return {
				TabCur: 0,
				scrollLeft: 0,
				pageNo: 1,
				pageSize: 20,
				loadMoreText: '到底了',
				total: 0,
				shop: [],
				tabars: [{
					id: 0,
					name: '精选直播'
				}, {
					id: 1,
					name: '我的关注'
				}, {
					id: 2,
					name: '蔬菜水果'
				}, {
					id: 3,
					name: '生活用品'
				}],
				lists:this.LiveList,
				swiperList: [
					{
						id: 1,
						type: 'image',
						url: 'https://ossweb-img.qq.com/images/lol/web201310/skin/big10001.jpg'
					},
					{
						id: 2,
						type: 'image',
						url: 'https://ossweb-img.qq.com/images/lol/web201310/skin/big25011.jpg'
					},
					{
						id: 3,
						type: 'image',
						url: 'https://ossweb-img.qq.com/images/lol/web201310/skin/big21016.jpg'
					},
					{
						id: 4,
						type: 'image',
						url: 'https://ossweb-img.qq.com/images/lol/web201310/skin/big99008.jpg'
					}
				],
				swiper_current: 1
				
				
			};
		},
		onLoad: function(prop) {

		},
		onShow() {
			this.pageNo = 1;
			//this.onInit(0);
		}, //下拉刷新
		onPullDownRefresh: function() {
			var that = this;
			this.loadMoreText = '';
			this.pageNo = 1;
			setTimeout(function() {
				that.onInit(1);
			}, 500);
		}, //上拉加载更多
		onReachBottom() {
			this.pageNo++;
			if (this.pageNo > this.total) {
				this.loadMoreText = '没有更多数据了!';
				return;
			}
			setTimeout(() => {
				this.onInit();
			}, 500);
		}, //分享页面
		onShareAppMessage: function(res) {
			if (res.from === 'button') {
				// 来自页面内分享按钮
				console.log(res.target);
			}
			let params = "token=" + this.userinfo.uid;
			return this.util.getSharePage(params);
		},
		methods: {
			...mapMutations(['setinviter']),
			onInit: function(type) {
				let that = this;
				this.$controller.onHome(this.pageNo, this.$store.state, type, function(data, error, msg) {
					console.log(data);
					if (error == 0) {
						that.total = data.total;  
						if (that.pageNo == 1) {
							that.shop = data.shop;
						} else {
							that.shop = that.shop.concat(data.shop);
						}
					}
				});
			},
			toPage: function(e) {
				let url = e.currentTarget.dataset.url;
				if (!url) {
					return
				}
				uni.navigateTo({
					url: url
				})
			},
			onNavBar: function(e) {

			},
			OnSwiper: function(e) {
				this.swiper_current = e + 1; 
			},
			OnClickLive: function(id) {
				
				uni.navigateTo({
					url: '../webview/webview'
				})
			},
			onSwitch(e) {
				switch (parseInt(e)) {
					case 1:
						uni.redirectTo({
							url: '../shops/shop'
						})
						break;
					case 2:
						uni.redirectTo({
							url: '../shopcar/shopcar'
						})
						break;
					case 3:
						uni.redirectTo({
							url: '../users/users'
						})
						break;
				}

			}
			
		}
	};
</script>

<style scoped>

</style>
